package com.lleice.common.entity.resp;

import com.lleice.common.enums.ExceptionEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 
 * @author lizihao
 *
 * @param <T>
 */
@Getter
@Setter
@Accessors(chain = true)
@ApiModel("基础响应体")
public class CommonRsp<T> extends BaseRsp {

    /**
	 * 
	 */
	private static final long serialVersionUID = -1908867884312317738L;
	@ApiModelProperty("响应数据")
    private T data;

    public static <T> CommonRsp<T> ok(T t) {
        return newCommonRsp(t, Result.ok());
    }

    public static <T> CommonRsp<T> fail() {
        return newCommonRsp(null, Result.fail());
    }

    public static <T> CommonRsp<T> fail(String msg) {
        return newCommonRsp(null, Result.fail(msg));
    }
    public static <T> CommonRsp<T> fail(ExceptionEnum exception) {
        return newCommonRsp(null, Result.fail(exception));
    }
    private static <T> CommonRsp<T> newCommonRsp(T data, Result result) {
        CommonRsp<T> rsp = new CommonRsp<>();
        rsp.setData(data);
        rsp.setResult(result);
        return rsp;
    }
}
